///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2003 Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////

#ifndef _IXMLPARSER_H
#define _IXMLPARSER_H

#include "tringle/xml.h"
#include "xmlbuffer.h"

// XMLParser definitions
#define QUOT        "&quot;"
#define LT          "&lt;"
#define GT          "&gt;"
#define APOS        "&apos;"
#define AMP         "&amp;"
#define ESC_HEX     "&#x"
#define ESC_DEC     "&#"

typedef struct XmlNameSpaceURI
{
    char                        *nsURI;
    char                        *prefix;
    struct XmlNameSpaceURI   *nextNsURI;
} XmlNameSpaceURI;


typedef struct XmlElementStack
{
    char                    *element;
    char                    *prefix;
    char                    *namespaceUri;
    XmlNameSpaceURI            *pNsURI;
    struct XmlElementStack    *nextElement;
} XmlElementStack;


typedef enum
{
    E_ELEMENT,
    E_ATTRIBUTE,
    E_CONTENT,
} XmlParserState;

typedef struct XmlParser
{
    char            *dataBuffer;	//data buffer
    char            *curPtr;		//ptr to the token parsed
    char            *savePtr;		//Saves for backup
    XmlBuffer     lastElem;
    XmlBuffer     tokenBuf;

    XmlNode           *pNeedPrefixNode;
    XmlElementStack   *pCurElement;
    XmlNode           *currentNodePtr;
    XmlParserState        state;

    BOOL                bHasTopLevel;

} XMLParser;



int     XmlParserLoadDocument( XmlDocument **retDoc, char * xmlFile, BOOL file);
BOOL    XmlParserIsValidXmlName( DOMString name);
int     XmlParserSetNodePrefixAndLocalName(XmlNode *   node);
void    XmlParserFreeNodeContent( XmlNode *   node);

void    XmlAttrFree(IN XmlAttribute *attrNode);
void    XmlAttrInit(IN XmlAttribute *attrNode);

int     XmlElementSetTagName(XmlElement *element, char *tagName);

void    XmlNamedNodeMapInit(XmlNamedNodeMap *nnMap);
int     XmlNamedNodeMapAddToNamedNodeMap(XmlNamedNodeMap **nnMap, XmlNode *  add);

void    XmlNodeInit(XmlNode *   node);
BOOL    XmlNodeCompare(XmlNode *   left, XmlNode *   right);

void    XmlNodeGetElementsByTagName( XmlNode *  n, char *tagname, XmlNodeList **list);
void    XmlNodeGetElementsByTagNameNS( XmlNode *   node, char *namespaceURI,
        char *localName, XmlNodeList **list);

int     XmlNodeSetNodeProperties(XmlNode* node, XmlNode *  src);
int     XmlNodeSetNodeName( XmlNode* node, DOMString qualifiedName);

void    XmlNodeListInit(XmlNodeList *nList);
int     XmlNodeListAddToNodeList(XmlNodeList **nList, XmlNode *  add);

#endif  // _IXMLPARSER_H

